<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>spring boot annotations | haijd</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="Spring Annotations" />
  
  
  
  
  <meta name="description" content="Spring Boot注解概览、入门">
<meta name="keywords" content="Spring Annotations">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring Boot Annotations">
<meta property="og:url" content="http://www.hais2.com/2018/06/14/Spring-Boot-Annotations-1/index.html">
<meta property="og:site_name" content="haijd">
<meta property="og:description" content="Spring Boot注解概览、入门">
<meta property="og:locale" content="default">
<meta property="og:image" content="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1528780019766&di=68e5f2f2eef5b87bf5b5d54455fe994f&imgtype=jpg&src=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D2161947716%2C2940818680%26fm%3D214%26gp%3D0.jpg">
<meta property="og:updated_time" content="2018-06-14T06:43:55.353Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Spring Boot Annotations">
<meta name="twitter:description" content="Spring Boot注解概览、入门">
<meta name="twitter:image" content="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1528780019766&di=68e5f2f2eef5b87bf5b5d54455fe994f&imgtype=jpg&src=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D2161947716%2C2940818680%26fm%3D214%26gp%3D0.jpg">
  
    <link rel="alternate" href="/atom.xml" title="haijd" type="application/atom+xml">
  
  <link rel="icon" href="/css/images/favicon.ico">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/9749f0/00000000000000000001008f/27/l?subset_id=2&fvd=n5) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/90cf9f/000000000000000000010091/27/l?subset_id=2&fvd=n7) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/8a5494/000000000000000000013365/27/l?subset_id=2&fvd=n4) format("woff2");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/d337d8/000000000000000000010095/27/l?subset_id=2&fvd=i4) format("woff2");font-weight:400;font-style:italic;}</style>
    
  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Yanone+Kaffeesatz%3A200%2C300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">
  <link rel="stylesheet" href="/css/style.css">

  <script src="/js/jquery-3.1.1.min.js"></script>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css" >
  <link rel="stylesheet" href="/css/hiero.css" >
  <link rel="stylesheet" href="/css/glyphs.css" >
  
    <link rel="stylesheet" href="/css/vdonate.css" >
  

</head>

<script>
var themeMenus = {};

  themeMenus["/"] = "Home"; 

  themeMenus["/archives"] = "Archives"; 

  themeMenus["/categories"] = "Categories"; 

  themeMenus["/tags"] = "Tags"; 

  themeMenus["/about"] = "About"; 

</script>


  <body data-spy="scroll" data-target="#toc" data-offset="50">


  <header id="allheader" class="site-header" role="banner">
  <div class="clearfix container">
      <div class="site-branding">

          <h1 class="site-title">
            
              <a href="/" title="haijd" rel="home"> haijd </a>
            
          </h1>

          
            <div class="site-description">Stay Hungry,Stay Foolish</div>
          
            
          <nav id="main-navigation" class="main-navigation" role="navigation">
            <a class="nav-open">Menu</a>
            <a class="nav-close">Close</a>
            <div class="clearfix sf-menu">

              <ul id="main-nav" class="nmenu sf-js-enabled">
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/">Home</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/archives">Archives</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/categories">Categories</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/tags">Tags</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/about">About</a> </li>
                    
              </ul>
            </div>
          </nav>


      </div>
  </div>
</header>




  <div id="container">
    <div id="wrap">
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-Spring-Boot-Annotations-1" style="width: 66%; float:left;" class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
<div class="article-gallery">
  <div class="article-gallery-photos">
    
      <a class="article-gallery-img fancybox" href="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1528780019766&di=68e5f2f2eef5b87bf5b5d54455fe994f&imgtype=jpg&src=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D2161947716%2C2940818680%26fm%3D214%26gp%3D0.jpg" rel="gallery_cjie4nak9006o3swaxrejy01l">
        <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1528780019766&di=68e5f2f2eef5b87bf5b5d54455fe994f&imgtype=jpg&src=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D2161947716%2C2940818680%26fm%3D214%26gp%3D0.jpg" itemprop="image">
      </a>
    
  </div>
</div>

    
      <header class="article-header">
        
  
    <h1 class="thumb" class="article-title" itemprop="name">
      Spring Boot Annotations
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	Posted on <a href="/2018/06/14/Spring-Boot-Annotations-1/" class="article-date">
	  <time datetime="2018-06-14T03:00:01.000Z" itemprop="datePublished">June 14, 2018</time>
	</a>

      
	<span id="busuanzi_container_page_pv">
	  本文总阅读量<span id="busuanzi_value_page_pv"></span>次
	</span>

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <blockquote>
<p>原文地址：<a href="http://www.baeldung.com/spring-boot-annotations" target="_blank" rel="noopener">http://www.baeldung.com/spring-boot-annotations</a><br>此篇为译文，由于英语水平有限，可能对原文的理解有误，欢迎指正，不甚感激！<br><!-- TOC --></p>
</blockquote>
<ul>
<li><a href="#1">1. 概览</a></li>
<li><a href="#2-springbootapplication">2. <code>@SpringBootApplication</code></a></li>
<li><a href="#3-enableautoconfiguration">3. <code>@EnableAutoConfiguration</code></a></li>
<li><a href="#4-auto-configuration">4. Auto-Configuration条件注解</a><ul>
<li><a href="#41-conditionalonclassconditionalonmissingclass">4.1. <code>@ConditionalOnClass</code>与<code>@ConditionalOnMissingClass</code></a></li>
<li><a href="#42-conditionalonbeanconditionalonmissingbean">4.2. <code>@ConditionalOnBean</code>与<code>@ConditionalOnMissingBean</code></a></li>
<li><a href="#43-conditionalonproperty">4.3. <code>@ConditionalOnProperty</code></a></li>
<li><a href="#44-conditionalonresource">4.4. <code>@ConditionalOnResource</code></a></li>
<li><a href="#45-conditionalonwebapplicationconditionalonnotwebapplication">4.5. <code>@ConditionalOnWebApplication</code>与<code>@ConditionalOnNotWebApplication</code></a></li>
<li><a href="#46-conditionalexpression">4.6. <code>@ConditionalExpression</code></a></li>
<li><a href="#47-conditional">4.7. <code>@Conditional</code></a></li>
</ul>
</li>
<li><a href="#5">5. 总结</a></li>
</ul>
<!-- /TOC -->
<h1 id="1-概览"><a href="#1-概览" class="headerlink" title="1. 概览"></a>1. 概览</h1><p>Spring Boot的自动配置功能使创建Spring配置变得非常容易。</p>
<p>在这个入门教程，我们将要探讨Spring Boot相关的注解，其注解来自于两个包：<code>org.springframework.boot.autoconfigure</code>和<code>org.springframework.boot.autoconfigure.condition</code>。<br><a id="more"></a></p>
<h1 id="2-SpringBootApplication"><a href="#2-SpringBootApplication" class="headerlink" title="2. @SpringBootApplication"></a>2. <code>@SpringBootApplication</code></h1><p>我们使用这个注解在Spring Boot应用中创建一个入口类(main class)：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">VehicleFactoryApplication</span></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>&#123;</span><br><span class="line">        SpringApplication.run(VehicleFactoryApplication.class, args);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><code>@SpringBootApplication</code>注解封装了<code>@Configuration</code>、<code>@EnableAutoConfiguration</code>和<code>@ComponentScan</code>这三个注解的功能和默认属性。</p>
<h1 id="3-EnableAutoConfiguration"><a href="#3-EnableAutoConfiguration" class="headerlink" title="3. @EnableAutoConfiguration"></a>3. <code>@EnableAutoConfiguration</code></h1><p><code>@EnableAutoConfiguration</code>注解就像它的名字一样：启用自动注解。这意味着Spring Boot会在其类路径中查找并且自动配置bean，然后自动应用它们。</p>
<p>Note：我们必须同时使用<code>@Configuration</code>注解：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableAutoConfiguration</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">VehicleFactoryConfig</span></span>&#123;&#125;</span><br></pre></td></tr></table></figure></p>
<h1 id="4-Auto-Configuration条件注解"><a href="#4-Auto-Configuration条件注解" class="headerlink" title="4. Auto-Configuration条件注解"></a>4. Auto-Configuration条件注解</h1><p>通常情况下，当我们编写自定义自动配置(auto-configurations)的时候，我们想要Spring有条件的使用它们，我们可以使用本节中介绍的注解来实现这一点。</p>
<p>我们可以将本节中介绍的注释放置在<code>@Configuration</code>类或<code>@Bean</code>方法上。</p>
<p>在接下来的部分中，我将仅仅介绍基础的相关概念，需要更进一步的了解，请查阅<a href="http://www.baeldung.com/spring-boot-custom-auto-configuration" target="_blank" rel="noopener">这篇文章</a>。</p>
<h2 id="4-1-ConditionalOnClass与-ConditionalOnMissingClass"><a href="#4-1-ConditionalOnClass与-ConditionalOnMissingClass" class="headerlink" title="4.1. @ConditionalOnClass与@ConditionalOnMissingClass"></a>4.1. <code>@ConditionalOnClass</code>与<code>@ConditionalOnMissingClass</code></h2><p>使用这个条件注解，Spring会根据注解参数中传入的类存在与否，来判断是否使用这个<code>@Configuration</code>类。(博主注：<code>@ConditionalOnClass({Source.class, Data.class})</code>表示当<code>Source</code>和<code>Data</code>这两个类存在的时候，才使用被标记的类，<code>@ConditionalOnMissingClass</code>则正好相反。)<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@ConditionalOnClass</span>(DataSource.class)</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MySQLAutoconfiguration</span> </span>&#123;</span><br><span class="line">    <span class="comment">//...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="4-2-ConditionalOnBean与-ConditionalOnMissingBean"><a href="#4-2-ConditionalOnBean与-ConditionalOnMissingBean" class="headerlink" title="4.2. @ConditionalOnBean与@ConditionalOnMissingBean"></a>4.2. <code>@ConditionalOnBean</code>与<code>@ConditionalOnMissingBean</code></h2><p>当我们想使用一个具体的bean是否存在作为特定条件的时候，就可以使用这两个注解：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="meta">@ConditionalOnBean</span>(name = <span class="string">"dataSource"</span>)</span><br><span class="line"><span class="function">LocalContainerEntityManagerFactoryBean <span class="title">entityManagerFactory</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="4-3-ConditionalOnProperty"><a href="#4-3-ConditionalOnProperty" class="headerlink" title="4.3. @ConditionalOnProperty"></a>4.3. <code>@ConditionalOnProperty</code></h2><p>使用该注解，我们可以为属性(properties)的值设置一个特定条件：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="meta">@ConditionalOnProperty</span>(</span><br><span class="line">    name = <span class="string">"usemysql"</span>, </span><br><span class="line">    havingValue = <span class="string">"local"</span></span><br><span class="line">)</span><br><span class="line"><span class="function">DataSource <span class="title">dataSource</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="4-4-ConditionalOnResource"><a href="#4-4-ConditionalOnResource" class="headerlink" title="4.4. @ConditionalOnResource"></a>4.4. <code>@ConditionalOnResource</code></h2><p>我们可以使用这个注解，让Spring在指定的资源存在的时候才使用被标注的定义：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ConditionalOnResource</span>(resources = <span class="string">"classpath:mysql.properties"</span>)</span><br><span class="line"><span class="function">Properties <span class="title">additionalProperties</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="4-5-ConditionalOnWebApplication与-ConditionalOnNotWebApplication"><a href="#4-5-ConditionalOnWebApplication与-ConditionalOnNotWebApplication" class="headerlink" title="4.5. @ConditionalOnWebApplication与@ConditionalOnNotWebApplication"></a>4.5. <code>@ConditionalOnWebApplication</code>与<code>@ConditionalOnNotWebApplication</code></h2><p>通过这个注解，我们可以设置一个条件，当前的应用是否是一个web应用：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ConditionalOnWebApplication</span></span><br><span class="line"><span class="function">HealthCheckController <span class="title">healthCheckController</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="4-6-ConditionalExpression"><a href="#4-6-ConditionalExpression" class="headerlink" title="4.6. @ConditionalExpression"></a>4.6. <code>@ConditionalExpression</code></h2><p>在复杂的情况下我们可以使用该注解，当SpEL表达式的结果为<code>true</code>的时候，Spring才会使用被标注的定义：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="meta">@ConditionalOnExpression</span>(<span class="string">"$&#123;usemysql&#125; &amp;&amp; $&#123;mysqlserver == 'local'&#125;"</span>)</span><br><span class="line"><span class="function">DataSource <span class="title">dataSource</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="4-7-Conditional"><a href="#4-7-Conditional" class="headerlink" title="4.7. @Conditional"></a>4.7. <code>@Conditional</code></h2><p>甚至在更复杂的条件下，我们可以创建一个自定义的条件注解，<code>@Conditional</code>会告诉Spring使用这个自定义的条件：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Conditional</span>(HibernateCondition.class)</span><br><span class="line"><span class="function">Properties <span class="title">additionalProperties</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="comment">//...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h1 id="5-总结"><a href="#5-总结" class="headerlink" title="5. 总结"></a>5. 总结</h1><p>在本篇中，我们展示了一个概览，如何在微调自动配置，对自动配置设置一个条件。</p>
<p>同样的，本片中的示例代码可以在我们的<a href="https://github.com/eugenp/tutorials/tree/master/spring-mvc-java" target="_blank" rel="noopener">GitHub</a>上获取。</p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
	<span class="ico-folder"></span>
    <a class="article-category-link" href="/categories/Java/">Java</a>

      
  <span class="ico-tags"></span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Spring-Annotations/">Spring Annotations</a></li></ul>

      
        <div id="donation_div"></div>

<script src="/js/vdonate.js"></script>
<script>
var a = new Donate({
  title: '如果觉得我的文章对您有用，请随意打赏。您的支持将鼓励我继续创作!', // 可选参数，打赏标题
  btnText: 'Donate', // 可选参数，打赏按钮文字
  el: document.getElementById('donation_div'),
  wechatImage: '/css/images/wechatPay.png',
  alipayImage: '/css/images/alipay.jpg'
});
</script>
      

      
        
	<section id="comments" class="comment">
	  <div id="disqus_thread">
	  <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
	  </div>
	</section>

	<script type="text/javascript">
	var disqus_shortname = 'haijdblog';
	(function(){
	  var dsq = document.createElement('script');
	  dsq.type = 'text/javascript';
	  dsq.async = true;
	  dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
	  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	}());
	(function(){
	  var dsq = document.createElement('script');
	  dsq.type = 'text/javascript';
	  dsq.async = true;
	  dsq.src = '//' + disqus_shortname + '.disqus.com/count.js';
	  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	}());
	</script>


      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
  
    <a href="/2018/06/14/Vue-ElementUI-upload-file-controller/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Vue-ElementUI upload组件的上传文件控制</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">Contents</strong>
    
      <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-概览"><span class="nav-number">1.</span> <span class="nav-text">1. 概览</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-SpringBootApplication"><span class="nav-number">2.</span> <span class="nav-text">2. @SpringBootApplication</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-EnableAutoConfiguration"><span class="nav-number">3.</span> <span class="nav-text">3. @EnableAutoConfiguration</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#4-Auto-Configuration条件注解"><span class="nav-number">4.</span> <span class="nav-text">4. Auto-Configuration条件注解</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#4-1-ConditionalOnClass与-ConditionalOnMissingClass"><span class="nav-number">4.1.</span> <span class="nav-text">4.1. @ConditionalOnClass与@ConditionalOnMissingClass</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-2-ConditionalOnBean与-ConditionalOnMissingBean"><span class="nav-number">4.2.</span> <span class="nav-text">4.2. @ConditionalOnBean与@ConditionalOnMissingBean</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-3-ConditionalOnProperty"><span class="nav-number">4.3.</span> <span class="nav-text">4.3. @ConditionalOnProperty</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-4-ConditionalOnResource"><span class="nav-number">4.4.</span> <span class="nav-text">4.4. @ConditionalOnResource</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-5-ConditionalOnWebApplication与-ConditionalOnNotWebApplication"><span class="nav-number">4.5.</span> <span class="nav-text">4.5. @ConditionalOnWebApplication与@ConditionalOnNotWebApplication</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-6-ConditionalExpression"><span class="nav-number">4.6.</span> <span class="nav-text">4.6. @ConditionalExpression</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-7-Conditional"><span class="nav-number">4.7.</span> <span class="nav-text">4.7. @Conditional</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#5-总结"><span class="nav-number">5.</span> <span class="nav-text">5. 总结</span></a></li></ol>
    
    </div>
  </aside>
</section>
        
      </div>
      <footer id="footer" class="site-footer">
  

  <div class="clearfix container">
      <div class="site-info">
	      &copy; 2018 haijd All Rights Reserved.
          
            <span id="busuanzi_container_site_uv">
              本站访客数<span id="busuanzi_value_site_uv"></span>人次  
              本站总访问量<span id="busuanzi_value_site_pv"></span>次
            </span>
          
      </div>
      <div class="site-credit">
        Theme by <a href="https://github.com/iTimeTraveler/hexo-theme-hiero" target="_blank">hiero</a>
      </div>
  </div>
</footer>


<!-- min height -->

<script>
    var contentdiv = document.getElementById("content");

    contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/scripts.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/main.js"></script>








	<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js" async=""></script>
</body>
</html>
